home *** CD-ROM | disk | FTP | other *** search
/ SGI Freeware 1999 August / SGI Freeware 1999 August.iso / dist / fw_FileRunner.idb / usr / freeware / lib / FileRunner2.5 / config.tcl.z / config.tcl
Encoding:
Text File  |  1999-01-26  |  33.3 KB  |  1,084 lines

  1.  
  2.  
  3. proc AddConf { fid var_var setto expl } {
  4.   global glob config 
  5.   upvar $var_var var
  6.   puts -nonewline $fid {#-----------------------------------------------------------------------}
  7. #-----------------------------------------------------------------------
  8.   #puts -nonewline $fid "# Variable: $var_var"
  9.   puts $fid "$expl"
  10.   if { $setto == "" } {
  11.     puts $fid "set $var_var \{$var\}"
  12.   } else {
  13.     puts -nonewline $fid "set $var_var $setto"
  14.   }
  15.   puts $fid ""
  16. }
  17.  
  18. proc SaveConfig {}  {
  19.   global glob config env
  20.   set r [catch {open $glob(conf_dir)/config w} fid]
  21.   if {$r != 0} { PopError "Saving config: $fid"; return "" }
  22.  
  23. puts $fid "# Generated by FileRunner $glob(version) on [clock format [clock seconds]]"
  24.   
  25.   puts $fid {
  26. # This is the configuration file for FileRunner. It is read every time
  27. # FileRunner starts up. It is saved in your home directory as
  28. # "~/.fr/config" (~ is short for the path to your home directory). Make
  29. # sure to only edit values for variables that are listed. Do not add or
  30. # delete anything, since this file will be automatically regenerated
  31. # when you do a "Edit Configuration->Save Configuration" in the menu and those
  32. # changes will be lost.
  33. #
  34. # This config file is saved to disk and reread into FileRunner when you
  35. # press the OK button in the config browser. You can also edit this file
  36. # with a regular text editor and re-read it into FileRunner with
  37. # "Configuration->Reread Configuration"
  38. }
  39.  
  40.   AddConf $fid config(hotlist) "{" {
  41. # This list is what will show up in your HotList menu. (Like "bookmarks"
  42. # in Netscape). Feel free to edit this list.
  43. }
  44.   foreach k $glob(hotlist) {
  45.     if { [lindex $k 1] != "" } {
  46.       puts $fid "    {$k}"
  47.     } else {
  48.       puts $fid "    $k"
  49.     }
  50.   }
  51.   puts $fid "  }\n"
  52.  
  53.   puts $fid {
  54. #****** COMMAND CONFIGURATION ******************************************
  55. }
  56.  
  57.   AddConf $fid config(editor) "" {
  58. # This variable should be set to the name of your favourite text
  59. # editor. This editor will be invoked when you select files and press
  60. # the "Edit" button. The text editor you choose should be an
  61. # X-application, not a text-terminal application. You can start
  62. # text-terminal edtiors for example by launching them from inside an
  63. # xterm. E.g: "xterm -e vi %s". The editor you choose should be able to
  64. # load multiple files specified as arguments to the editor (e.g: 
  65. # "emacs /tmp/foo /home/joe/bar"). The editor will be launched in the
  66. # background.
  67. }
  68.  
  69.   AddConf $fid config(view,extensions) "" {
  70. # This parameter contains a list of commands and the file patterns that
  71. # are used when finding the right viewer for various files. The commands
  72. # will receive a list of selected files. The first file in the selected
  73. # list are used when deciding which viewer should be used. (Don't try
  74. # and view a couple of text files and images simultaneously by selecting
  75. # and pressing the view button). If you add a the option "-viewtext"
  76. # last in the rule that means the command outputs a listing/view and it
  77. # should be viewed in the internal text viewer. The viewing commands
  78. # will be executed in the background.
  79. }
  80.  
  81.   AddConf $fid config(cmd,print) "" {
  82. # The print command you want to use to print files.
  83. }
  84.  
  85.   AddConf $fid config(cmd,term) "" {
  86. # The name of your favourite terminal program.
  87. # This is the program that will be launched when you press the button
  88. # with the image of the terminal window (upper right of the file list
  89. # panels). It will be launched in the background.
  90. }
  91.  
  92.   AddConf $fid config(cmd,diff) "" {
  93. # Your favourite diff command. Should be able to diff directories also.
  94. # Used in the "Diff" button command. This program will run
  95. # synchronously, i.e. FileRunner will wait until it's done.
  96. }
  97.  
  98.   puts $fid {
  99. #****** ARCHIVER/PACKER CONFIGURATION **********************************
  100. }
  101.  
  102.   AddConf $fid config(cmd,unarc,extensions) "" {
  103. # Extensions and bindings for unarchive rules. This is a list of
  104. # commands and file name extensions. FileRunner will use this variable
  105. # when deciding which command should be used to unarchive the file when
  106. # you press the UnArc button.
  107. }
  108.  
  109.   AddConf $fid config(cmd,unpack,extensions) "" {
  110. # Extensions and bindings for unpacking rules. This is a list of
  111. # commands and file name extensions. FileRunner will use this variable
  112. # when deciding which command should be used to unpack the file when you
  113. # press the UnPack button.
  114. }
  115.  
  116.   AddConf $fid config(cmd,pack) "" {
  117. # The name of your favourite packer command. 
  118. # Used in the "Arc" button command to pack files. Run synchronously
  119. # or in the background.
  120. }
  121.  
  122.   AddConf $fid config(cmd,archive) "" {
  123. # This is the name of your archiver program. The archiver program is
  124. # passed the name of the directory selected and is executed in the
  125. # current directory. The archive created is supposed to contain the
  126. # contents of the directory. The default builtin "tar+gz {%s}" creates
  127. # an archive named <directory>.tar.gz packed with tar and gzip. This
  128. # command is used in the "Arc" button command to pack/archive
  129. # directories. Can be run synchronously or in the background.
  130. }
  131.  
  132.   puts $fid {
  133. #****** FTP CONFIGURATION **********************************************
  134. }
  135.  
  136.   AddConf $fid config(ftp,login) "" {
  137. # Rule based login information. Allows automatic determination
  138. # if the login should use a proxy and what username/password it
  139. # should use etc.
  140. # See the online guide, chapter 8.8.
  141. }
  142.  
  143.   AddConf $fid config(ftp,fastlink) "" {
  144. # Set this to 1 if you feel your FTP connections are fast, to 0
  145. # otherwise. If you set it to 1, soft-links in FTP listings are
  146. # correctly identified either as links to directories or to files,
  147. # otherwise it will always think links are links to directories.
  148. }
  149.  
  150.   AddConf $fid config(ftp,proxy) "" {
  151. # If you have to go through a firewall via an FTP proxy, set this
  152. # variable to the hostname of your FTP proxy. Set it to "" if you don't
  153. # have an FTP proxy.
  154. }
  155.  
  156. #  AddConf $fid config(ftp,user) "" {
  157. # Set username for FTP sessions. If you are doing anonymous FTP, set
  158. # this to "anonymous".
  159. #}
  160.  
  161.   AddConf $fid config(ftp,password) "" {
  162. # Set password for anonymous FTP sessions. This should be your 
  163. # email address.
  164. }
  165.  
  166.   AddConf $fid config(ftp,timeout) "" {
  167. # Set timeout in seconds for FTP communication. 
  168. }
  169.  
  170.   AddConf $fid config(ftp,anonymous) "" {
  171. # 1 -> Do anonymous FTP
  172. # 0 -> Log in to FTP with username and password.
  173. }
  174.  
  175.   AddConf $fid config(ftp,useproxy) "" {
  176. # 1 -> Use defined ftp proxy
  177. # 0 -> Don't use proxy (to access hosts inside the proxy/firewall)
  178. }
  179.  
  180.   AddConf $fid config(ftp,cache,maxentries) "" {
  181. # Maximum number of directory listings the cache should hold.
  182. }
  183.  
  184.   AddConf $fid config(ftp,cd_pwd) "" {
  185. # If true (non-zero): When doing a cd to a new directory, FileRunner
  186. # will run pwd to check where it ended up (which makes a difference
  187. # if you cd to a link which points to a directory).
  188. }
  189.  
  190.   puts $fid {
  191. #****** HTTP CONFIGURATION *********************************************
  192. }
  193.  
  194.   AddConf $fid config(http,proxy) "" {
  195. # HTTP proxy. Format: host:port (for example: proxy.foo.com:80). 
  196. # Leave empty if you have a direct connection to the net.
  197. }
  198.  
  199.   puts $fid {
  200. #****** APPEARANCE CONFIGURATION ***************************************
  201. }
  202.  
  203.   AddConf $fid config(gui,color_bg) "" {
  204. # Background color of listboxes etc.
  205. # You can edit this easier from the configuration menu.
  206. }
  207.  
  208.   AddConf $fid config(gui,color_fg) "" {
  209. # Foreground color of listboxes etc.
  210. # You can edit this easier from the configuration menu.
  211. }
  212.  
  213.   AddConf $fid config(gui,color_cmd) "" {
  214. # Color for commands in the command window.
  215. # You can edit this easier from the configuration menu.
  216. }
  217.  
  218.   AddConf $fid config(gui,color_select_bg) "" {
  219. # Selection background color.
  220. # You can edit this easier from the configuration menu.
  221. }
  222.  
  223.   AddConf $fid config(gui,color_select_fg) "" {
  224. # Selection foreground color.
  225. # You can edit this easier from the configuration menu.
  226. }
  227.  
  228.   AddConf $fid config(gui,color_scheme) "" {
  229. # Scheme color.
  230. # Default Tk seems to be "grey85".
  231. # You can edit this easier from the configuration menu.
  232. }
  233.  
  234.   AddConf $fid config(gui,color_cursor) "" {
  235. # Cursor color.
  236. # You can edit this easier from the configuration menu.
  237. }
  238.  
  239.   AddConf $fid config(gui,font) "" {
  240. # Font for listboxes etc. Must be fixed-width.
  241. # Some good choices:
  242. #  screen-bold-12
  243. #  *-lucidatypewriter-bold-r-normal-*-12-*
  244. #  *-lucidatypewriter-bold-r-normal-*-14-*
  245. #  *-courier-bold-r-normal-*-14-*
  246. }
  247.  
  248.   AddConf $fid config(gui,font_scheme) "" {
  249. # Font for default Tcl/Tk stuff (menus, buttons etc.)
  250. # Set this to "" in order to not change from what it already is.
  251. # Default Tk seems to be "-Adobe-Helvetica-Bold-R-Normal--*-120-*-*-*-*-*-*"
  252. }
  253.  
  254.   AddConf $fid config(geometry,main) "" {
  255. # The X11 geometry string deciding where and how big the FileRunner
  256. # main window should be at startup.
  257. }
  258.  
  259.   AddConf $fid config(geometry,textviewer) "" {
  260. # The X11 geometry string deciding where and how big the FileRunner
  261. # text viewer window should be.
  262. }
  263.  
  264.   AddConf $fid config(geometry,qedit) "" {
  265. # The X11 geometry string deciding where and how big the FileRunner
  266. # quick-editor window should be.
  267. }
  268.  
  269.   AddConf $fid config(middle_button_colors) "" {
  270. # This contains a list of background colors for the middle row command
  271. # buttons. The syntax is:
  272. #  set config(middle_button_colors) {
  273. #    { ButtonName [-]Color }
  274. #    ...
  275. #  }
  276. # An example:
  277. #  set config(middle_button_colors) {
  278. #    { Copy #0000ff }
  279. #    { Delete red }
  280. #    { Move -red }
  281. #  }
  282. # The Copy button will be blue and the Delete button will be red.
  283. # The Move button will turn red only when the mouse moves over it.
  284. # Buttons not mentioned will get the default scheme color.
  285. # You need to restart FileRunner for this to have effect.
  286. }
  287.  
  288.   puts $fid {
  289. #****** SHELL CONFIGURATION ********************************************
  290. }
  291.  
  292.   AddConf $fid config(shell,height,left) "" {
  293. # Height in lines of text of the left shell text window.
  294. }
  295.  
  296.   AddConf $fid config(shell,height,right) "" {
  297. # Height in lines of text of the right shell text window.
  298. }
  299.  
  300.   AddConf $fid config(shell,buffer) "" {
  301. # Size of shell buffer, in lines of text.
  302. }
  303.  
  304.   AddConf $fid config(shell,aliases) "{" {
  305. # Shell aliases, in the form of a list of tuples: " { alias, command } .. "
  306. # If there are arguments to the command line they are just tagged onto the
  307. # alias. (I.e, aliases can take arguments)
  308. }
  309.   foreach k $config(shell,aliases) {
  310.     if { [lindex $k 1] != "" } {
  311.       puts $fid "    {$k}"
  312.     } else {
  313.       puts $fid "    $k"
  314.     }
  315.   }
  316.   puts $fid "  }\n"
  317.  
  318.   puts $fid {
  319. #****** MISC CONFIGURATION *********************************************
  320. }
  321.  
  322.   AddConf $fid config(startpwd,left) "" {
  323. # At startup, show this directory in the left panel.
  324. # If you set it to "", FileRunner will show the directory from where 
  325. # it was invoked.
  326. }
  327.  
  328.   AddConf $fid config(startpwd,right) "" {
  329. # At startup, show this directory in the right panel
  330. # If you set it to "", FileRunner will show the directory from where 
  331. # it was invoked.
  332. }
  333.  
  334.   AddConf $fid config(fileshow,all) "" {
  335. # 1 -> Will show files beginning with a dot ".".
  336. # 0 -> Won't.
  337. }
  338.  
  339.   AddConf $fid config(fileshow,sort) "" {
  340. # This variable determines how file listings are sorted. Possible values
  341. # are "nameonly", "dirsfirst", "dirslast", "time" and "size"
  342. }
  343.  
  344.   AddConf $fid config(dateformat) "" {
  345. # Sets date format. Possible values "yymmdd" and "ddmmyy".
  346. # (yy=year mm=month dd=day)
  347. }
  348.  
  349.   AddConf $fid config(autoupdate) "" {
  350. # Sets how often FileRunner checks to see if it needs to update its 
  351. # windows.
  352. # Set this to 0 to disable. Value is in seconds.
  353. }
  354.  
  355.   AddConf $fid config(logsize) "" {
  356. # Size of log in bytes. Don't set this too high, or FileRunner might 
  357. # slow down a little. When the log exceeds this size, it will be 
  358. # truncated.  
  359. }
  360.  
  361.   AddConf $fid config(check_ownership) "" {
  362. # If this is "1", FileRunner will check as best as it can if you are
  363. # about to overwrite or delete a file you do not own and warn you about
  364. # it. This can be handy when working in groups with other people and you
  365. # want an extra check that you don't accidentally erase someone elses
  366. # files.  This will slow some operations down slightly.
  367. }
  368.  
  369.   AddConf $fid config(keyb_support) "" {
  370. # If this is 1, you will make the file listbox take focus when clicked
  371. # and this will let you use the keyboard for traversing the list (using
  372. # arrows and PgUp/PgDown) and issuing commands.
  373. # You'll have to restart FileRunner to get this setting to have effect.
  374. }
  375.  
  376.   AddConf $fid config(ask,dir_delete) "" {
  377. # If 1, FileRunner will ask you if you are sure when you delete 
  378. # directories. If 0, it will go ahead and delete without asking.
  379. }
  380.  
  381.   AddConf $fid config(ask,file_delete) "" {
  382. # If 1, FileRunner will ask you if you are sure when you delete 
  383. # files. If 0, it will go ahead and delete without asking.
  384. }
  385.  
  386.   AddConf $fid config(mwheel,delta) "" {
  387. # For "wheel"-mice (MS Intellimouse or Logitech MouseMan+), set
  388. # number of lines to scroll when turning mouse wheel.
  389. }
  390.  
  391.   AddConf $fid config(mwheel,neg) "" {
  392. # For "wheel"-mice (MS Intellimouse or Logitech MouseMan+), set
  393. # mouse button to use for negative scroll movement.
  394. }
  395.  
  396.   AddConf $fid config(mwheel,pos) "" {
  397. # For "wheel"-mice (MS Intellimouse or Logitech MouseMan+), set
  398. # mouse button to use for positive scroll movement.
  399. }
  400.  
  401.   AddConf $fid config(save_conf_at_exit) "" {
  402. # If true (non-zero): FileRunner will automatically save configuration and
  403. # hotlist at exit.
  404. }
  405.  
  406.   AddConf $fid config(create_relative_links) "" {
  407. # If true (non-zero): FileRunner will create relative links
  408. # instead of absolute links. (e.g ../../foo instead of /a/b/c/foo)
  409. }
  410.  
  411.   AddConf $fid config(cd_pwd) "" {
  412. # If true (non-zero): When doing a cd to a new directory, FileRunner
  413. # will run pwd to check where it ended up (which makes a difference
  414. # if you cd to a link which points to a directory).
  415. }
  416.  
  417.  
  418.   puts $fid {
  419. #****** DANGEROUS CONFIGURATION ****************************************
  420. # Below this point you can change some of the stuff that is used
  421. # internally by FileRunner. This should almost never be necessary if the
  422. # platform is standard Unix or close to standard Unix. If you change any
  423. # of this below, make very very sure you get it right. If you are
  424. # unsure, don't touch it. If you get it wrong, very bad things can
  425. # happen...
  426. # A note on having the full path to the commands below, like using
  427. # "/bin/cp" and not just "cp": Lets say you have a dot "." in your path
  428. # and someone really mean has created a command called "cp" in his home
  429. # directory that does a "rm" instead. Then you cd to his home directory
  430. # and type cp <something>, you will invoke his evil manipulated version
  431. # of cp that removes whatever you inteded to copy. The morale of this is
  432. # to always use full path to critical commands and hope your sysop is
  433. # not so mean he will rename "/bin/rm" to "/bin/mkdir"...
  434. # A few commands below do not have specified full path, that's because
  435. # they aren't very critical and seem to move around between different
  436. # versions of Unix.
  437. }
  438.  
  439.   AddConf $fid config(cmd,sh) "" {
  440. # The bourne-shell command. This should almost always be /bin/sh.
  441. }
  442.  
  443.   AddConf $fid config(cmd,rm) "" {
  444. # The rm (remove-files) command. This should almost always be /bin/rm.
  445. }
  446.  
  447.   AddConf $fid config(cmd,cp) "" {
  448. # The cp (copy-files) command. This should almost always be /bin/cp.
  449. }
  450.  
  451.   AddConf $fid config(cmd,ln) "" {
  452. # The ln (link) command. This should almost always be /bin/ln.
  453. }
  454.  
  455.   AddConf $fid config(cmd,chmod) "" {
  456. # The change mode (chmod) command. This should almost always be /bin/chmod.
  457. }
  458.  
  459.   AddConf $fid config(cmd,touch) "" {
  460. # The touch command.
  461. }
  462.  
  463.   AddConf $fid config(cmd,du) "" {
  464. # The "du" command. Should return size in kilobytes. On many
  465. # systems other than BSD (?) you need to add a -k argument
  466. # to this command to get it in kilobytes.
  467. }
  468.  
  469.   AddConf $fid config(cmd,find) "" {
  470. # The find command.
  471. }
  472.  
  473.   close $fid
  474.   Log "Configuration saved to $glob(conf_dir)/config"
  475. }
  476.  
  477. proc InitConfig {} {
  478.   global glob config env argv
  479.  
  480.   set config(hotlist) ""
  481.   if {[info exists env(EDITOR)]} {
  482.     set config(editor) "$env(EDITOR) {%s}"
  483.   } else {
  484.     set config(editor) "xterm -e vi {%s}"
  485.   }
  486.   set config(fileshow,all) 0
  487.   set config(fileshow,sort) "dirsfirst"
  488.  
  489.   set config(cmd,print) "lpr {%s}"
  490.   set config(cmd,term) "xterm"
  491.   set config(cmd,diff) "diff -r {%s} {%s}"
  492.   set config(cmd,pack) "gzip {%s}"
  493.   set config(cmd,archive) "tar+gz {%s}"
  494.  
  495.   set config(cmd,unarc,extensions) {
  496.   { {gzip -cd {%s} | tar xfBp -}
  497.     {*.tgz *.taz *.tar.z *.tar.gz} }
  498.   { {tar xfBp {%s}}
  499.     {*.tar} }
  500.   { {unzip -oqq {%s}}
  501.     {*.zip} }
  502.   { {lha -x {%s}}
  503.     {*.lha} }
  504. }
  505.  
  506.   set config(cmd,unpack,extensions) {
  507.   { {gzip -d {%s}}
  508.     {*.gz} }
  509. }
  510.  
  511.   set config(startpwd,left) ""
  512.   set config(startpwd,right) ""
  513.   set config(ask,dir_delete) "1"
  514.   set config(ask,file_delete) "0"
  515.   set config(ftp,fastlink) 0
  516.   set config(ftp,proxy) ""
  517.   set config(ftp,user) anonymous
  518.   set config(ftp,password) ""
  519.   set config(ftp,timeout) "120"
  520.   set config(ftp,anonymous) 1
  521.   set config(ftp,useproxy) 1
  522.   set config(ftp,login) {}
  523.   set config(ftp,cache,maxentries) 15
  524.   set config(ftp,cd_pwd) 1
  525.   set config(http,proxy) {}
  526.   #set config(gui,color_bg) FloralWhite
  527.   set config(gui,color_bg) {#e8b3e570deed}
  528.   set config(gui,color_fg) Black
  529.   set config(gui,color_cmd) "#ffffe4e679db"
  530.   set config(gui,color_select_bg) "#f1a9ec43aa9d"
  531.   set config(gui,color_select_fg) black
  532.   set config(gui,color_scheme) "grey85"
  533.   #set config(gui,color_scheme) {#bfeed0add9da}
  534.   set config(gui,color_cursor) black
  535.   set config(gui,font_scheme) ""
  536.  
  537.   foreach testfont { 
  538.       *-lucidatypewriter-bold-r-normal-*-12-*
  539.       screen-bold-12 
  540.       *-lucidatypewriter-bold-r-normal-*-14-*
  541.       *-courier-bold-r-normal-*-14-* 
  542.       fixed 
  543.       } {
  544.     set config(gui,font) $testfont
  545.     set r [catch { label .foo -font $testfont } out]
  546.     catch {destroy .foo}
  547.     #puts "$r $out"
  548.     if {$r == 0} {
  549.       break
  550.     }
  551.   }
  552.  
  553.   set config(middle_button_colors) {
  554.   { Delete -#ff4d4d }
  555. }
  556.  
  557.   set config(keyb_support) 0
  558.   set config(dateformat) "yymmdd"
  559.   set config(autoupdate) 20
  560.   set config(logsize) 5000
  561.   set config(check_ownership) 0
  562.   set config(geometry,main) "840x720+31+0"
  563.   set config(geometry,textviewer) "80x30"
  564.   set config(geometry,qedit) "80x30"
  565.   set config(shell,height,left) 10
  566.   set config(shell,height,right) 10
  567.   set config(shell,buffer) 1000
  568.   set config(shell,aliases) {{.. {cd ..}} {md mkdir} {m view} {more view} {less view}}
  569.   set config(view,extensions) {
  570.   { {xmikmod {%s}}
  571.     {*.mod.gz *.s3m *.mtm *.stm *.xm *.uni *.mod} }
  572.   { {timidity {%s}}
  573.     {*.midi.gz *.midi *.mid.gz *.mid} }
  574.   { {xv -gamma 2.0 {%s}}
  575.     { *.bmp *.iff *.jpg *.pbm *.pgm *.png *.ppm *.tga *.tif *.tiff *.xbm *.xpm *.gif} }
  576.   { {gzip -dc {%s} | ghostview -}
  577.     { *.ps.gz } }
  578.   { {ghostview {%s}}
  579.     { *.ps } }
  580.   { {xanim {%s}}
  581.     {*.avi *.fli *.flc *.mpg} }
  582.   { {gzip -cd {%s} | tar tvf -} 
  583.     { *.tgz *.taz *.tar.z *.tar.gz }
  584.     -viewtext }
  585.   { {tar tvf {%s}}
  586.     {*.tar}
  587.     -viewtext }
  588.   { {unzip -lv {%s}}
  589.     {*.zip}
  590.     -viewtext }
  591.   { {lha -v {%s}}
  592.     {*.lha}
  593.     -viewtext }
  594.   { {gzip -cd {%s}}
  595.     {*.gz}
  596.     -viewtext }
  597.   { {rpm -qilp {%s}}
  598.     {*.rpm}
  599.     -viewtext }
  600. }
  601.  
  602.   set config(cmd,sh) "/bin/sh"
  603.   set config(cmd,rm) "/bin/rm"
  604.   set config(cmd,cp) "/bin/cp"
  605.   set config(cmd,ln) "/bin/ln"
  606.   set config(cmd,chmod) "/bin/chmod"
  607.   set config(cmd,touch) "touch"
  608.   set config(cmd,du) "du -s"
  609.   set config(cmd,find) find
  610.  
  611.   set config(mwheel,delta) 6
  612.   set config(mwheel,neg) <4>
  613.   set config(mwheel,pos) <5>
  614.  
  615.   set config(save_conf_at_exit) 1
  616.  
  617.   set config(create_relative_links) 1
  618.   set config(cd_pwd) 1
  619.  
  620.   set glob(searchstring) ""
  621.   set glob(log) ""
  622.   set glob(left,pwd)  [Pwd]
  623.   set glob(right,pwd) [Pwd]
  624.   set glob(left,update_oldpwd) $glob(left,pwd)
  625.   set glob(right,update_oldpwd) $glob(right,pwd)
  626.   set glob(left,newpwd_oldpwd) $glob(left,pwd)
  627.   set glob(right,newpwd_oldpwd) $glob(right,pwd)
  628.   set glob(left,filelist) {}
  629.   set glob(right,filelist) {}
  630.   set glob(hotlist) {}
  631.   set glob(toplevelidx) 0
  632.   set glob(entry_dialog_return) {}
  633.   set glob(ftp_entry_dialog_return) {}
  634.   set glob(ftp,serverport,start) 5000
  635.   set glob(ftp,serverport,end) 65000
  636.   # This is an ugly hack to avoid reusing ports too fast, but it's because of a limitiation in the tcl socket
  637.   # command. (You can't make the socket -server command choose a port by itself...)
  638.   set glob(ftp,serverport,last) [expr 5000 + (([pid] * 100) % (65000 - 5000))]
  639.   set glob(ftp,serversocket,acceptlist) {}
  640.   set glob(forceupdate) 0
  641.   set glob(havedoneftp) 0
  642.   set glob(enableautoupdate) 1
  643.   set glob(left,df) ?
  644.   set glob(right,df) ?
  645.   set glob(abortcmd) 0
  646.   set glob(left,dirstack) ""
  647.   set glob(right,dirstack) ""
  648.   set glob(left,shell,packed) 0
  649.   set glob(right,shell,packed) 0
  650.   set glob(shell,maxed) 0
  651.   set glob(left,shell,history) {}
  652.   set glob(right,shell,history) {}
  653.   set glob(left,shell,complete,flipping) 0
  654.   set glob(right,shell,complete,flipping) 0
  655.   set glob(left,shell,history,flipping) 0
  656.   set glob(right,shell,history,flipping) 0
  657.   set glob(left,shell,history,flipping,index) 0
  658.   set glob(right,shell,history,flipping,index) 0
  659.   set glob(batchlist) {}
  660.   set glob(tmpdir) $glob(conf_dir)/tmp
  661.  
  662.   set glob(win,top) .fupper.ftop
  663.   set glob(win,left) .fupper.fleft
  664.   set glob(win,right) .fupper.fright
  665.   set glob(win,middle) .fupper.fmiddle
  666.   set glob(win,bottom) .flower
  667.  
  668.   set glob(gui,color_xx,winlist) ""
  669.   set glob(gui,color_cmd,winlist) ""
  670.   set glob(gui,color_scheme,winlist) ""
  671.   set glob(gui,tablist) ""
  672.  
  673.   # These configuration have already been incorporated, since they are used when creating
  674.   # new widgets. (No widgets have been created yet)
  675.   set glob(gui,color_bg)      $config(gui,color_bg)
  676.   set glob(gui,color_fg)      $config(gui,color_fg)
  677.   set glob(gui,color_cmd)     $config(gui,color_cmd)
  678.   set glob(gui,color_select_bg)  $config(gui,color_select_bg)
  679.   set glob(gui,color_select_fg)  $config(gui,color_select_fg)
  680.   # These configuration have not been set yet, must be done in ReConfigColors
  681.   set glob(gui,color_scheme) ""
  682.   set glob(gui,font_scheme) ""
  683.   set glob(gui,color_cursor) ""
  684.  
  685.   set glob(gui,font) $config(gui,font)
  686.   set glob(gui,font_scheme) ""
  687.  
  688.   set glob(async) 0
  689.   set glob(left,shellcount) 0
  690.   set glob(right,shellcount) 0
  691.  
  692.   if {![info exists env(USER)]} {
  693.     if {![info exists env(LOGNAME)]} {
  694.       PopError "Cannot read \$USER or \$LOGNAME environment variable. FileRunner cannot work without this correctly set."
  695.       CleanUp 1
  696.     }
  697.     set env(USER) $env(LOGNAME)
  698.   }
  699.   if {![info exists env(HOME)]} {
  700.     PopError "Cannot read \$HOME environment variable. FileRunner cannot work without this correctly set."
  701.     CleanUp 1
  702.   }
  703.   if {![info exists env(HOST)]} {
  704.     set env(HOST) unknown
  705.   }
  706.   if {$env(HOST) == "unknown"} {
  707.     set r [catch { exec uname -n } out]
  708.     if {!$r} {
  709.       set env(HOST) $out
  710.     }
  711.   }
  712.  
  713.   set glob(history) ""
  714.   # read history from disk
  715.   if { [file exists $glob(conf_dir)/history ] } {
  716.     set r [catch {set fid [open $glob(conf_dir)/history r];gets $fid glob(history);close $fid} out]
  717.     if {$r} {
  718.       puts "FileRunner: Can't read directory history from disk: $out"
  719.     }
  720.   }
  721.  
  722.   # set up a few default options
  723. #  option add *HighlightThickness 1 widgetDefault
  724.   option add *InsertWidth 2 widgetDefault
  725.   option add *Scrollbar.Width 11 widgetDefault
  726.   option add *Button.BorderWidth 1 widgetDefault
  727.   option add *Scrollbar.BorderWidth 2 widgetDefault
  728. #  option add *Listbox.BorderWidth 2 widgetDefault # makes the spacing between list elements too large...
  729.   option add *Frame.BorderWidth 2 widgetDefault
  730.   option add *Entry.BorderWidth 2 widgetDefault
  731. #  option add *.Text.InsertBackground red widgetDefault
  732. #  option add *insertBorderWidth 2 widgetDefault
  733. #  option add *BorderWidth 1 widgetDefault
  734. }
  735.  
  736. proc ReadConfig {} {
  737.   global glob config env argv argv0
  738.   if {[file readable $glob(lib_fr)/config]} {
  739.     set r [catch {source $glob(lib_fr)/config} out]
  740.     if {$r} {
  741.       tk_dialog .error_dialog "Init error" "Reading system wide configuration from $glob(lib_fr)/config:\n$out" error 0 "OK"
  742.     }
  743.   }
  744.   if {[file readable $glob(conf_dir)/config]} {
  745.     set r [catch {source $glob(conf_dir)/config} out]
  746.     if {$r} {
  747.       tk_dialog .error_dialog "Init error" "Reading user configuration $glob(conf_dir)/config:\n$out" error 0 "OK"
  748.     }
  749.   }
  750.   set glob(hotlist) $config(hotlist)
  751.   if {$config(ftp,password) == "" } {
  752.     set r [catch {set config(ftp,password) "$env(USER)@[exec domainname]"}]
  753.   }
  754.   foreach k { left right } {
  755.     if { $config(startpwd,$k) != "" && !$glob(init_done)} {
  756.       catch { cd $config(startpwd,$k); set glob($k,pwd) [Pwd] } out
  757.     }
  758.   }
  759.   if { $config(ftp,proxy) == "" } {
  760.     set config(ftp,useproxy) 0
  761.   }
  762.   if { $config(dateformat) == "ddmmyy" } {
  763.     GetTimeFromSecsSetFormat 1
  764.   }
  765.   if { $config(dateformat) == "yymmdd" } {
  766.     GetTimeFromSecsSetFormat 0
  767.   }
  768.   ReConfigColors
  769.   ReConfigFont
  770. }
  771.  
  772. proc ConfigPwd {} {
  773.   global glob config env argv argv0
  774.   set pwd(left) [lindex $argv 1]
  775.   set pwd(right) [lindex $argv 2]
  776.   foreach k { left right } {
  777.     if { $pwd($k) != "" && $glob($k,pwd) != $pwd($k) } {
  778.       NewPwd $k $pwd($k)
  779.       UpdateWindow $k
  780.     } else {
  781.       if { $config(startpwd,$k) != "" && $glob($k,pwd) != $config(startpwd,$k)} {
  782.         NewPwd $k $config(startpwd,$k) 
  783.         UpdateWindow $k
  784.       }
  785.     }
  786.   }
  787.   AppendToDirHistory $glob(left,pwd)
  788.   AppendToDirHistory $glob(right,pwd)
  789.   set glob(left,dirstack) $glob(left,pwd)
  790.   set glob(right,dirstack) $glob(right,pwd)
  791. }
  792.  
  793. proc CheckConfigDir {} {
  794.   global env glob
  795.  
  796.   if {[file isdirectory $glob(conf_dir)]} {
  797.     return
  798.   }
  799.   if {$glob(os) != "WIN32" && [file exists $env(HOME)/.fr]} {
  800.     set button [tk_dialog .questDialog "Question" \
  801.         "The configuration files have moved for this version of FileRunner. Is it OK to move the config files to \
  802. the new directory $env(HOME)/.fr? (The old .fr file will be called .fr/config, the .fr_cmds file will be called .fr/cmds \
  803. and the .fr_history file will be called .fr/history)" \
  804.         question 0 "Yes" "No(Exit)"]
  805.     if {$button == 1} {
  806.       exit 0
  807.     }
  808.     set cmds { 
  809.       "file rename $env(HOME)/.fr $env(HOME)/.fr_tmp" 
  810.       "file mkdir $env(HOME)/.fr"
  811.       "file rename $env(HOME)/.fr_tmp $env(HOME)/.fr/config" 
  812.     }
  813.     foreach cmd $cmds {
  814.       set r [catch $cmd out]
  815.       if {$r} {
  816.         PopErrorSimple "$cmd : $out"
  817.         exit 1
  818.       }
  819.     }
  820.     set cmds { 
  821.       "file rename $env(HOME)/.fr_cmds $env(HOME)/.fr/cmds" 
  822.       "file rename $env(HOME)/.fr_history $env(HOME)/.fr/history" 
  823.       "file rename $env(HOME)/.fr_ver $env(HOME)/.fr/version" }
  824.     foreach cmd $cmds {
  825.       set r [catch $cmd out]
  826.     }
  827.     return
  828.   }
  829.   set button [tk_dialog .questDialog "Question" \
  830.       "The FileRunner configuration directory $glob(conf_dir) does not exist. Ok to create it?" \
  831.       error 0 "Yes" "No"]
  832.   if {$button == 1} {
  833.     return
  834.   }
  835.   set r [catch "file mkdir $glob(conf_dir)" out]
  836.   if {$r} {
  837.     PopErrorSimple "$out"
  838.     exit 1
  839.   }
  840. }
  841.  
  842. proc ConfigBrowser {} {
  843.   global glob config
  844.  
  845.   if {![file exists $glob(conf_dir)/config]} { SaveConfig }
  846.  
  847.   set glob(edit_configuration_configlist) {
  848.     {Hotlist {---------------------------}}
  849.     hotlist
  850.     {Commands {COMMAND CONFIGURATION}}
  851.     editor
  852.     view,extensions
  853.     cmd,print
  854.     cmd,term
  855.     cmd,diff
  856.     {Archiver/Packer {ARCHIVER/PACKER}}
  857.     cmd,unarc,extensions
  858.     cmd,unpack,extensions
  859.     cmd,pack
  860.     cmd,archive
  861.     {FTP {FTP CONFIGURATION}}
  862.     ftp,login
  863.     ftp,fastlink
  864.     ftp,proxy
  865.     ftp,password
  866.     ftp,timeout
  867.     ftp,anonymous
  868.     ftp,useproxy
  869.     ftp,cache,maxentries
  870.     ftp,cd_pwd
  871.     {HTTP {HTTP}}
  872.     http,proxy
  873.     {Appearance {APPEARANCE}}
  874.     gui,color_bg
  875.     gui,color_fg
  876.     gui,color_cmd
  877.     gui,color_select_bg
  878.     gui,color_select_fg
  879.     gui,color_scheme
  880.     gui,color_cursor
  881.     gui,font
  882.     gui,font_scheme
  883.     geometry,main
  884.     geometry,textviewer
  885.     geometry,qedit
  886.     middle_button_colors
  887.     {Shell {SHELL}}
  888.     shell,height,left
  889.     shell,height,right
  890.     shell,buffer
  891.     shell,aliases
  892.     {Miscellaneous {MISC}}
  893.     startpwd,left
  894.     startpwd,right
  895.     fileshow,all
  896.     fileshow,sort
  897.     dateformat
  898.     autoupdate
  899.     logsize
  900.     check_ownership
  901.     keyb_support
  902.     ask,dir_delete
  903.     ask,file_delete
  904.     mwheel,delta
  905.     mwheel,neg
  906.     mwheel,pos
  907.     save_conf_at_exit
  908.     create_relative_links
  909.     cd_pwd
  910.     {{Dangerous stuff} {DANGEROUS}}
  911.     cmd,sh
  912.     cmd,rm
  913.     cmd,cp
  914.     cmd,ln
  915.     cmd,chmod
  916.     cmd,touch
  917.     cmd,du
  918.     cmd,find
  919.   }
  920.  
  921.   set w .config_dialog
  922.   toplevel $w -class Dialog
  923.   wm title $w "Configuration Browser"
  924.   wm iconname $w "FR config browser"
  925.   wm resizable $w true true
  926.   wm transient $w [winfo toplevel [winfo parent $w]]
  927.  
  928.   frame $w.left
  929.   frame $w.right
  930.   frame $w.bot
  931.  
  932.   # Create left frame containing the list of config options
  933.   scrollbar $w.left.scrollvert -command "$w.left.list yview" -orient vertical 
  934.   listbox $w.left.list \
  935.     -yscrollcommand "$w.left.scrollvert set" \
  936.     -font $config(gui,font) \
  937.     -background $config(gui,color_bg) -foreground $config(gui,color_fg) \
  938.     -selectbackground $config(gui,color_select_bg) -selectforeground $config(gui,color_select_fg) \
  939.     -width 25 \
  940.     -height 35 
  941.   pack $w.left.list -side left -fill both
  942.   pack $w.left.scrollvert -side right -fill y
  943.  
  944.   # Create right frame containing the config text and a scrollbar
  945.   text $w.right.text -relief sunken -bd 2 -yscrollcommand "$w.right.scroll set" -setgrid 1 \
  946.       -height 35 -font $config(gui,font) -background $config(gui,color_bg) \
  947.       -foreground $config(gui,color_fg) -selectbackground $config(gui,color_select_bg) -selectforeground $config(gui,color_select_fg) -highlightthickness 0 
  948.   scrollbar $w.right.scroll -command "$w.right.text yview" 
  949.   pack $w.right.scroll -side right -fill y
  950.   pack $w.right.text -expand 1 -fill both
  951.  
  952.   # Create bottom frame containing the OK/Cancel buttons
  953.   button $w.bot.regen -text {Regenerate Configuration} -command "ConfigBrowserRegenerate $w.right.text"
  954.   button $w.bot.ok -text OK -command "ConfigBrowserOK $w.right.text; destroy $w"
  955.   button $w.bot.cancel -text Cancel -command "set glob(config_dialog_return) {}; destroy $w"
  956.   pack $w.bot.cancel -side right -padx 3
  957.   pack $w.bot.ok -side right -padx 3
  958.   pack $w.bot.regen -side right -padx 3
  959.  
  960.   # Fill left frame with contents
  961.   #set glob(font_dialog,fl) [split $glob(font_dialog,fl) "\n"]
  962.   set cdl {}
  963.   foreach k $glob(edit_configuration_configlist) {
  964.     if {[lindex $k 1] != {}} {
  965.       lappend cdl [lindex $k 0]
  966.     } else {
  967.       set tmp [split $k ,_]
  968.       set tmp2 {}
  969.       foreach t $tmp {
  970.         lappend tmp2 "[string toupper [string index $t 0]][string range $t 1 end]"
  971.       }
  972.       lappend cdl "  $tmp2"
  973.     }
  974.   }
  975.  
  976.   eval $w.left.list insert end $cdl
  977.  
  978.   # Create popup menu
  979.   menu $w.right.text.p
  980.   $w.right.text.p add command -label Search... -command "SearchView $w.right.text 0"
  981.   $w.right.text.p add command -label {Search Again} -command "SearchView $w.right.text 1"
  982.  
  983.   # Pack the top frames
  984.   pack $w.bot -side bottom
  985.   pack $w.left -side left -fill both
  986.   pack $w.right -side right -fill both -expand 1
  987.  
  988.   # Assign bindings
  989.   bind $w.right.text $config(mwheel,neg) "$w.right.text yview scroll -$config(mwheel,delta) units"
  990.   bind $w.right.text $config(mwheel,pos) "$w.right.text yview scroll $config(mwheel,delta) units"
  991.   bind $w.left.list $config(mwheel,neg) "$w.left.list yview scroll -$config(mwheel,delta) units"
  992.   bind $w.left.list $config(mwheel,pos) "$w.left.list yview scroll $config(mwheel,delta) units"
  993.   bind $w <Next> "$w.right.text yview scroll 1 pages"
  994.   bind $w <Prior> "$w.right.text yview scroll -1 pages"
  995.   bind $w <Home> "$w.right.text see 0.0"
  996.   bind $w <End> "$w.right.text see end"
  997.   bind $w <Escape> "destroy $w"
  998.   bind $w.right.text <3> "tk_popup $w.right.text.p %X %Y"
  999.   bind $w.left.list <1> "ConfigBrowserJumpToLoc $w.right.text \[$w.left.list nearest %y\]"
  1000.   wm withdraw $w
  1001.   update idletasks
  1002.   set x [expr [winfo screenwidth $w]/2 - [winfo reqwidth $w]/2 \
  1003.           - [winfo vrootx [winfo parent $w]]]
  1004.   set y [expr [winfo screenheight $w]/2 - [winfo reqheight $w]/2 \
  1005.           - [winfo vrooty [winfo parent $w]]]
  1006.   wm geom $w +$x+$y
  1007.   wm deiconify $w
  1008.  
  1009.   # Fill right frame with contents
  1010.   set filename $glob(conf_dir)/config
  1011.   set r [catch {set fid [open $filename r]} out]
  1012.   if {$r} {
  1013.     PopError "Can't open $filename for editing"
  1014.     destroy $w
  1015.     return
  1016.   }
  1017.   $w.right.text insert 0.0 [read -nonewline $fid]
  1018.   close $fid
  1019.   $w.right.text mark set insert 0.0
  1020. }
  1021.  
  1022. proc ConfigBrowserJumpToLoc { w index } {
  1023.   global glob config
  1024.   set tmp [lindex $glob(edit_configuration_configlist) $index]
  1025.   if {[lindex $tmp 1] != {}} {
  1026.     set searchfor [lindex $tmp 1]
  1027.     set heading 1
  1028.   } else {
  1029.     set searchfor config($tmp)
  1030.     set heading 0
  1031.   }
  1032.  
  1033.   set tag select
  1034.   $w tag configure $tag -background $config(gui,color_select_bg) -foreground $config(gui,color_select_fg) 
  1035.   $w tag remove $tag 0.0 end
  1036.  
  1037.   set idx [$w search -count len -backwards -- $searchfor 0.0]
  1038.   if {$idx == ""} {
  1039.     PopWarn "Can't find that location in config file. Try to regenerate configuration and try again."
  1040.     return
  1041.   }
  1042.   $w mark set insert "$idx + $len chars"
  1043.   $w see end
  1044.   $w see insert
  1045.   set line [lindex [split $idx .] 0]
  1046.   if {$heading} {
  1047.     $w mark set insert $line.0
  1048.   } else {
  1049.     # search backwards for ------------ and make sure it's visible
  1050.     set idx [$w search -count len -backwards -- "-----------" insert]
  1051.     if {$idx != {}} {
  1052.       $w see $idx
  1053.     }
  1054.   }
  1055.   $w tag add $tag $line.0 [expr $line+1].0
  1056. }
  1057.  
  1058. proc ConfigBrowserOK { w } {
  1059.   global glob config
  1060.   set filename $glob(conf_dir)/config
  1061.   Log "Configuration Browser: Saving $filename"
  1062.   Try { set fid [open $filename w]
  1063.         puts -nonewline $fid [$w get 0.0 end]
  1064.         close $fid} "" 1
  1065.   ReadConfig
  1066.   ForceUpdate
  1067. }
  1068.  
  1069. proc ConfigBrowserRegenerate { w } {
  1070.   global glob
  1071.   SaveConfig
  1072.   set filename $glob(conf_dir)/config
  1073.   set r [catch {set fid [open $filename r]} out]
  1074.   if {$r} {
  1075.     PopError "Can't open $filename for editing"
  1076.     return
  1077.   }
  1078.   $w delete 0.0 end
  1079.   $w insert 0.0 [read -nonewline $fid]
  1080.   close $fid
  1081.   $w mark set insert 0.0
  1082. }
  1083.